package com.liqi.web.controller.dev;

import com.liqi.common.core.domain.R;
import com.liqi.dev.pojo.CfgBranchDTO;
import com.liqi.dev.pojo.CfgBranchVO;
import com.liqi.web.service.dev.CfgBranchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import javax.validation.Valid;
import java.util.List;

/**
 * @author tianye
 * @since 2022-04-14
 */
@Api(tags = "网点管理")
@RestController
@RequestMapping("/cfgBranch")
public class CfgBranchController {

    @Autowired
    private CfgBranchService cfgBranchService;
    private static CfgBranchController cfgBranchController;
    
    //实例化，不然类报空指针
    @PostConstruct
    private void init() {
    	cfgBranchController = this;
    	cfgBranchController.cfgBranchService = this.cfgBranchService;
    }

    @ApiOperation("复制网点")
    @PostMapping("/copy")
    private R copy(@Valid @RequestBody CfgBranchDTO cfgBranchDTO) {
        return cfgBranchController.cfgBranchService.copy(cfgBranchDTO);
    }

    @ApiOperation("办事网点树形列表")
    @ResponseBody
    @RequestMapping(value = "/branchTree", method = RequestMethod.GET)
    public R<List<CfgBranchVO>> branchTree() {
        List<CfgBranchVO> list = cfgBranchController.cfgBranchService.branchTree();
        return R.ok(list);
    }

}
